import org.junit.Test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;

/**
 * @Description TODO
 * @Date 2022/3/29 17:43
 * @Author eric ling
 */
public class ArrayUtil {
    public static int[] indexToElement(boolean[] setIndex, int[] setComb){
        int[] set = new int[setComb.length];
        int setCombIndex = 0;
        int order = -1;
        for (int i = 0;i<setIndex.length && setCombIndex< setComb.length; i++){
            if (setIndex[i]) order++;
            if (order == setComb[setCombIndex]){
                set[setCombIndex] = i;
                setIndex[i] = false;
                setCombIndex ++;
            }
        }
        return set;
    }

    public static int[] contactArray(int[] set1, int[] set2){
        int[] set = Arrays.copyOf(set1, set1.length + set2.length);
        System.arraycopy(set2, 0, set, set1.length, set2.length);
        return set;
    }

    public static int[] deleteSame(int[] set1,int[] set2){
        //todo 得到 set1 - set1 ∩ set2
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < set1.length; i++){
            boolean flag = true;
            for (int j = 0; j < set2.length; j++){
                if (set1[i] == set2[j]){
                    flag = false;
//                    break;
                }
            }
            if (flag){
                list.add(set1[i]);
            }
        }

        //对 list 集合里的元素进行去重
        HashSet hashSet = new HashSet(list);
        list.clear();
        list.addAll(hashSet);

        int[] set = list.stream().mapToInt(Integer::valueOf).toArray();
        return set;

    }

    @Test
    public void test(){
        int[] set1 = {1,2,8,4,9,6,0};
        int[] set2 = {7,8,9,0};
        int[] deleteSame = deleteSame(set1, set2);
        System.out.println(Arrays.toString(deleteSame));
    }




}
